<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateRecordTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('record', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '记录表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('source', 'string', ['default' => '', 'limit' => 128, 'comment' => '来源'])
            ->addColumn('link_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '关联id'])
            ->addColumn('uuid', 'char', ['default' => '', 'limit' => 36, 'comment' => '全局唯一标识符'])
            ->addColumn('module_id', 'integer', ['limit' => 11, 'null' => false, 'signed' => false, 'default' => 0, 'comment' => '模块id'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建人'])
            ->addColumn('created', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间'])
            ->addColumn('json', 'json', ['null' => true, 'comment' => '存储自定义字段']);
        $table->create();
    }

    public function down()
    {
        $this->table('record')->drop()->save();
    }
}
